﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Store
{
    public partial class 废料发货登记 : System.Web.UI.Page
    {
        protected string Notice = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = 0;
            if (!this.IsPostBack)
            {
                this.LeiBie.DataBind();
                this.GGList.DataBind();
                this.DWList.DataBind();
                this.FenChang.DataBind();

                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;
                Cmd.CommandText = @"SELECT 规格,单位  FROM 废料 where ID=" + LeiBie.Text;
                Cmd.CommandType = CommandType.Text;
                SqlDataReader Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {

                    this.Label_GuiGe.Text = Reader.GetString(0).Trim();
                    this.Label_DanWei.Text = Reader.GetString(1).Trim();

                    Reader.Close();
                }

                Conn.Close();
                Reader.Dispose();
                Cmd.Dispose();
                Conn.Dispose();
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out id);
                }

                if (id > 0)
                {
                    this.Label_ID.Text = id.ToString();
                    this.SqlDataSource1.SelectParameters["ID"].DefaultValue = this.Label_ID.Text;
                    this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
                }
                else
                {

                    DateTime d = DateTime.Today;
                    this.Date1.Text = d.ToLongDateString();
                }
            }
        }



        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string op = (string)this.Session["OperatorName"];
            if (op == null)
            {
                op = "";
            }
            if (this.Label_ID.Text == "0")
            {
                this.SqlDataSource1.InsertParameters["保管员"].DefaultValue = op;

                this.SqlDataSource1.Insert();
            }
            else
            {
                if (this.SqlDataSource1.Update() > 0)
                {
                    this.Notice = "·保存成功";
                }
            }
        }

        protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {

            //   this.DanWei.Text = ((int)e.Command.Parameters[2].Value).ToString();
            this.LeiBie.Text = ((int)e.Command.Parameters[1].Value).ToString();
            if (!Convert.IsDBNull(e.Command.Parameters[2].Value))
            {
                this.FenChang.Text = ((int)e.Command.Parameters[2].Value).ToString();
            }

            if (!Convert.IsDBNull(e.Command.Parameters[3].Value))
            {
                this.ShuLiang.Text = ((decimal)e.Command.Parameters[3].Value).ToString();
            }

            if (!Convert.IsDBNull(e.Command.Parameters[4].Value))
            {
                this.Date1.Text = ((DateTime)e.Command.Parameters[4].Value).ToLongDateString();
            }



        }

        protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {
            this.Label_ID.Text = e.Command.Parameters[0].Value.ToString();

            this.Notice = "·保存成功";
        }

        protected void LeiBie_SelectedIndexChanged(object sender, EventArgs e)
        {
            string id = this.LeiBie.Text;
            this.Label_GuiGe.Text = this.GGList.Items.FindByValue(id).Text;
            this.Label_DanWei.Text = this.DWList.Items.FindByValue(id).Text;
        }
    }
}
